<?php
class MY_Controller extends CI_Controller{

	function __construct()
	{
		parent::__construct();
		$this->theme = 'default';
		$this->url = $this->uri->segment(1);

	}

	function title($title)
	{
		if($title == 'home'){
	 	return $title_text = "Viabilis Admin";
		}else{
			return $title_text = $title." - Viabilis Admin";
		}
	}

	function tofloat($num) {
		$dotPos = strrpos($num, '.');
		$commaPos = strrpos($num, ',');
		$sep = (($dotPos > $commaPos) && $dotPos) ? $dotPos :
		((($commaPos > $dotPos) && $commaPos) ? $commaPos : false);
		 
		if (!$sep) {
			return floatval(preg_replace("/[^0-9]/", "", $num));
		}

		return floatval(
		preg_replace("/[^0-9]/", "", substr($num, 0, $sep)) . '.' .
		preg_replace("/[^0-9]/", "", substr($num, $sep+1, strlen($num)))
		);
	}

	function checkUserStatus()
	{
		if($this->aauth->control()){
			if( $this->aauth->is_banned($this->aauth->get_user_id()) ){
				return false;
			}else{
				return true;
			}
		}else{
			return false;
		}
	}
	
	 function control( $perm_par = null){

		if($perm_par == null){
			return $this->aauth->is_loggedin();
		}else{
			$perm_id = $this->aauth->get_perm_id($perm_par);
			$this->aauth->update_activity();

			// if user or user's group not allowed
			if ( ! $this->aauth->is_allowed($perm_id) or ! $this->aauth->is_group_allowed($perm_id) ){
				// echo $this->aauth->config_vars['no_access'];
				  //$this->CI->lang->line('no_access');
				return false;
			}else{
				return true;
			}
		}
	}
	
	function get_tasks()
	{
		return $doList = follow::find('all',array('conditions'=>array(' aauth_user_id = ? AND date_start > ? AND date_start < ?',$this->aauth->get_user_id(),date('Y-m-d'),date('Y-m-d',strtotime('+3 days'))),'order'=>'date_start asc'));
	}
	
	
}